import { getTopCategoryAPI} from '@/apis/category'
import {  ref,onMounted,watch } from 'vue'
import { useRoute } from 'vue-router'

export function useCategory() {
  const topCategory = ref({})
  const route = useRoute()
  const getTopCategory = async () =>{
    const res = await getTopCategoryAPI(route.params.id)
    
    topCategory.value = res.result
    // console.log(res)
  }

  onMounted(() => {
    getTopCategory()
  })

  watch(route,() => {
    getTopCategory()
    })
 
    return{
      topCategory
    }
}